<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="qualityList" @selection-change="handleSelectionChange" border style="width: 100%"
    height="600">
      <el-table-column type="selection" width="55" align="center" v-if="false"/>
      <!-- <el-table-column label="id" align="center" prop="qualityId" /> -->
      <el-table-column label="用户/项目" align="center" prop="name" />
      <el-table-column label="车型/样车	" align="center" prop="carTypeDetil" />
      <el-table-column label="反馈时间" align="center" prop="problemFeedbackTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.problemFeedbackTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车型" align="center" prop="carType" :formatter="carTypeFormat"  width="50"/>
      <el-table-column label="系统" align="center" prop="workSystem" :formatter="workSystemFormat"  width="50"/>
      <el-table-column label="组别" align="center" prop="code"  width="50"/>
      <el-table-column label="问题描述" align="center" prop="problemDescription" />
      <el-table-column label="原因分析" align="center" prop="causeAnalysis" />
      <el-table-column label="永久解决措施	" align="center" prop="permanentSolutions" />
      <el-table-column label="发生阶段" align="center" prop="problemStage" :formatter="problemStageFormat" width="80"/>
      <!-- <el-table-column label="合同号" align="center" prop="contractNo" /> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> 
  </div>
</template>

<script>
import { queryGroupsErrorDetail } from "@/api/statistics/errorrate/errorrate.js";
import {groupList} from "@/api/work/process";
export default {
  name: "Quality",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 质量信息表格数据
      qualityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
 
      // 问题反馈时间时间范围
      daterangeProblemFeedbackTime: [],
      // 车型(0牵引 1自卸 2专用 3宽体)字典
      carTypeOptions: [],
      //组别
      groupTypeOptions: [],
      // 系统(0整车 1动传 2底盘 3车身 4车电)字典
      workSystemOptions: [],
      // FMEA积累(0 已积累 1本次积累)字典
      isFmeaOptions: [],
      // 问题发生阶段(0生产 1售后 2试验 3试制)字典
      problemStageOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
   
      },
      // 表单参数
      form: {},
      
    };
  },
  props:{
    querygroupsErrorrateParam: {
      type: Object,
      required: false
    }
  },
  created() {
    this.getList();
    this.getDicts("qa_car_type").then(response => {
      this.carTypeOptions = response.data;
    });
    this.getDicts("qa_system_type").then(response => {
      this.workSystemOptions = response.data;
    });
    this.getDicts("qa_fmea_type").then(response => {
      this.isFmeaOptions = response.data;
    });
    this.getDicts("qa_stage_type").then(response => {
      this.problemStageOptions = response.data;
    });
  },
  methods: {
    /** 查询质量信息列表 */
    getList() {
      this.loading = true;
      queryGroupsErrorDetail(this.querygroupsErrorrateParam).then(response => {
        // console.log(this.querygroupsErrorrateParam,'-----------------')
        this.qualityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 车型(0牵引 1自卸 2专用 3宽体)字典翻译
    carTypeFormat(row) {
      return this.selectDictLabel(this.carTypeOptions, row.carType);
    },
    // 系统(0整车 1动传 2底盘 3车身 4车电)字典翻译
    workSystemFormat(row) {
      return this.selectDictLabel(this.workSystemOptions, row.workSystem);
    },
    // 组别字典
    handleGroupList(){
      groupList().then((response) => {
        this.groupTypeOptions = response.data;
      });
    },
    // 问题发生阶段(0生产 1售后 2试验 3试制)字典翻译
    problemStageFormat(row) {
      return this.selectDictLabel(this.problemStageOptions, row.problemStage);
    },   
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.qualityId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    selectChange(val){
        this.$forceUpdate();
    },

  }
};
</script>
